package com.kuang.dao.role;

import com.kuang.dao.BaseDao;
import com.kuang.pojo.Role;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class RoleDaoImpl implements RoleDao{
    public List<Role> getRoles(Connection connection) {

        String sql = "select * from smbms_role";
        ResultSet resultSet = null;
        PreparedStatement preparedStatement = null;
        List<Role> roleList = new ArrayList<Role>();
        Object[]  param = {};
        resultSet=BaseDao.execute(connection,sql,param,resultSet,preparedStatement);

        try {
            while(resultSet.next()){
                Role role = new Role();
                role.setRoleCode(resultSet.getString("roleCode"));
                role.setRoleName(resultSet.getString("roleName"));
                roleList.add(role);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            BaseDao.connectClose(connection,preparedStatement,resultSet);
        }
        System.out.println(roleList);
        return roleList;
    }
}
